package com.example.onlineeducation.ui.topic


import android.os.Bundle
import android.view.View
import com.example.onlineeducation.base.BaseFragment
import com.example.onlineeducation.data.constant.TopicType
import com.example.onlineeducation.databinding.TopicStudyFragmentBinding
import com.google.android.material.tabs.TabLayoutMediator
import com.yc.jetpacklib.recycleView.YcViewPagerAdapter

/*
* 专题
* */
class TopicStudyFragment(val type: String) :
    BaseFragment<TopicStudyFragmentBinding>(TopicStudyFragmentBinding::inflate) {

    override fun TopicStudyFragmentBinding.initView(view: View, savedInstanceState: Bundle?) {

        val viewPagerAdapter = YcViewPagerAdapter(
            mutableListOf(
                TopicChildFragment(type, TopicType.Status.ALL),
                TopicChildFragment(type, TopicType.Status.INCOMPLETE),
                TopicChildFragment(type, TopicType.Status.COMPLETED)
            ), requireActivity()
        )

        viewPagerStudy.adapter = viewPagerAdapter
        viewPagerStudy.offscreenPageLimit = 3
        TabLayoutMediator(tabLayoutStudy, viewPagerStudy) { tab, position ->
            when (type) {
                TopicType.Type.TOPIC -> tab.text = mutableListOf("全部", "未达标", "已达标")[position]
                TopicType.Type.EXAM -> tab.text = mutableListOf("全部", "未通过", "已通过")[position]
            }

        }.attach()
    }

}
